package com.netease.nim.uikit.xpopup.popuview

import android.content.Context
import android.view.View
import android.widget.TextView
import com.lxj.xpopup.core.CenterPopupView
import com.lxj.xpopup.util.XPopupUtils
import www.wen.com.common.R
import www.wen.com.common.lib.extension.getDrawableAgency
import www.wen.com.common.lib.extension.setOnClickListenerAgency
import www.wen.com.common.lib.helper.ConfirmFunction

/**
 * @author WEN
 * @Description:这是一个基础只有标题、内容、确认、取消的警告弹窗
 * @date 2021/3/3 14:53
 */
class InformPopupView(
        context: Context,
        val title: CharSequence,
        val content: CharSequence,
        private val confirmContent: CharSequence,
        val drawableStart: Int?  = R.drawable.ic_ban,
        val layoutId: Int = R.layout.popupview_inform_layout,
        var confirmFunction: ConfirmFunction? = null,
) : CenterPopupView(context), View.OnClickListener {

    private lateinit var enterView: TextView
    private lateinit var tvContent: TextView
    private lateinit var tvTitle: TextView

    override fun getImplLayoutId(): Int = layoutId

    override fun onClick(v: View) {

        when (v.id) {
            R.id.confirm -> {
                confirmFunction?.invoke(this@InformPopupView)

                if (popupInfo.autoDismiss) dismiss()
            }
        }
    }

    override fun onCreate() {
        super.onCreate()
        enterView = findViewById(R.id.confirm)
        tvContent = findViewById(R.id.tvContent)
        tvTitle = findViewById(R.id.tvTitle)
        tvContent.text = content
        tvTitle.text = title
        enterView.text = confirmContent

        drawableStart?.run {
            val draw = getDrawableAgency(drawableStart)
            draw!!.setBounds(0,0,draw!!.minimumWidth,draw.minimumHeight)
            tvTitle.setCompoundDrawables(draw,null,null,null)
        }

        setOnClickListenerAgency(this, enterView)
    }

    override fun getMaxWidth(): Int {
        return (XPopupUtils.getWindowWidth(context) * 0.8f).toInt()
    }

}


